//
//  ViewController.m
//  MyMicroBlog
//
//  Created by Apple on 16/9/20.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "ViewController.h"
#import "MainTabBar.h"
#import "MainNaviViewController.h"
@interface ViewController ()
    
    @end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    MainTabBar *tabBar = [[MainTabBar alloc]init];
    [self setValue:tabBar forKey:@"tabBar"];
    tabBar.composeButtonAcition = ^{
        NSLog(@"block调用过来的滴!");
    };
    UIViewController *homeVC = [self controllerWith:@"HomeTableViewController" andTitle:@"首页" andImageName:@"tabbar_home"];
    UIViewController *messageVC = [self controllerWith:@"MessageTableViewController" andTitle:@"消息" andImageName:@"tabbar_message_center"];
    UIViewController *discoverVC = [self controllerWith:@"DiscoverTableViewController" andTitle:@"发现" andImageName:@"tabbar_discover"];
    UIViewController *profileVC = [self controllerWith:@"ProfileTableViewController" andTitle:@"我的" andImageName:@"tabbar_profile"];
    self.viewControllers = @[homeVC,messageVC,discoverVC,profileVC];
    
}
    
-(UIViewController *)controllerWith:(NSString *)className andTitle:(NSString *)title andImageName:(NSString *)imageName{
    Class clz = NSClassFromString(className);
    UIViewController *vc = [[clz alloc]init];
    return [self controllerWith:vc withTitle:title andImageName:imageName];
}
    
-(UIViewController *)controllerWith:(UIViewController *)vc withTitle:(NSString *)title andImageName:(NSString *)imageName{
    vc.tabBarItem.image = [UIImage imageNamed:imageName];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} forState:UIControlStateSelected];
    [vc.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} forState:UIControlStateNormal];
    UINavigationController *navi = [[MainNaviViewController alloc]initWithRootViewController:vc];
    vc.title = title;
    return navi;
}
    
    @end
